﻿namespace USElections.Converters
{
    using System;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Media;
    using USElections.Utils;
    
    /// <summary>
    /// GroupToForegroundBrushValueConverter class.
    /// </summary>
    public class GroupToForegroundBrushValueConverter : IValueConverter
    {
        /// <summary>
        /// Set color based on the number of items in the ItemInGroup collection.
        /// </summary>
        /// <param name="value">The ItemInGroup object.</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>A SolidColorBrush object.</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ItemInGroup<Model.JSON.State> group = value as ItemInGroup<Model.JSON.State>;

            if (group != null)
            {
                if (!group.HasItems)
                {
                    return (SolidColorBrush)Application.Current.Resources["PhoneDisabledBrush"];
                }
                else
                {
                    return new SolidColorBrush(Colors.White);
                }
            }

            return (SolidColorBrush)Application.Current.Resources["PhoneDisabledBrush"];
        }

        /// <summary>
        /// Not implemented.
        /// </summary>
        /// <param name="value">The parameter is not used.</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>No return value.</returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
